package com.xique.door.service.impl;



import com.xique.common.core.text.Convert;
import com.xique.common.core.utils.DateUtils;
import com.xique.door.bean.domain.BuildUnit;
import com.xique.door.mapper.BuildUnitMapper;
import com.xique.door.service.IBuildUnitService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 单元Service业务层处理
 * 
 * @author caogq
 * @date 2021-09-09
 */
@Service
public class BuildUnitServiceImpl implements IBuildUnitService
{
    @Autowired
    private BuildUnitMapper buildUnitMapper;

    /**
     * 查询单元
     * 
     * @param id 单元ID
     * @return 单元
     */
    @Override
    public BuildUnit selectBuildUnitById(Long id)
    {
        return buildUnitMapper.selectBuildUnitById(id);
    }

    /**
     * 查询单元列表
     * 
     * @param buildUnit 单元
     * @return 单元
     */
    @Override
    public List<BuildUnit> selectBuildUnitList(BuildUnit buildUnit)
    {
        return buildUnitMapper.selectBuildUnitList(buildUnit);
    }

    /**
     * 新增单元
     * 
     * @param buildUnit 单元
     * @return 结果
     */
    @Override
    public int insertBuildUnit(BuildUnit buildUnit)
    {
        buildUnit.setCreateTime(DateUtils.getNowDate());
        return buildUnitMapper.insertBuildUnit(buildUnit);
    }

    @Override
    public int insertBuildUnits(List<BuildUnit> buildUnits) {
        if (CollectionUtils.isEmpty(buildUnits)) {
            return 1;
        }
        buildUnits.forEach(item -> {
            item.setCreateTime(DateUtils.getNowDate());
        });
        return buildUnitMapper.insertBuildUnits(buildUnits);
    }

    /**
     * 修改单元
     * 
     * @param buildUnit 单元
     * @return 结果
     */
    @Override
    public int updateBuildUnit(BuildUnit buildUnit)
    {
        buildUnit.setUpdateTime(DateUtils.getNowDate());
        return buildUnitMapper.updateBuildUnit(buildUnit);
    }

    /**
     * 删除单元对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteBuildUnitByIds(String ids)
    {
        return buildUnitMapper.deleteBuildUnitByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除单元信息
     * 
     * @param id 单元ID
     * @return 结果
     */
    @Override
    public int deleteBuildUnitById(Long id)
    {
        return buildUnitMapper.deleteBuildUnitById(id);
    }
}
